﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
using Breeze.ContextProvider;
using Breeze.ContextProvider.EF6;
using Breeze.Infrastructure;
using Breeze.WebApi2;
using Newtonsoft.Json.Linq;

namespace Breeze.Controllers
{

    [BreezeController]
    public class CustomerManagementController : ApiController
    {
        private EFContextProvider<SalesOrderContext> cm;

        public CustomerManagementController()
        {
            cm = new EFContextProvider<SalesOrderContext>();
        }

        [HttpGet]
        public string Metadata()
        {
            return cm.Metadata();
        }

        [HttpGet]
        public IQueryable<Customer> Customers()
        {
            return from cust in cm.Context.Customers
                orderby cust.LastName, cust.FirstName
                select cust;
        }

        [HttpPost]
        public SaveResult SaveChanges(JObject saveBundle)
        {
            return cm.SaveChanges(saveBundle);
        }
    }
}